#!/usr/bin/env python
# -*- coding: utf-8 -*-

# subflip - Prepare subtitle files for non-bidi-aware players.
# Copyright (C) 2006 Noam Raphael < spam.noam at gmail.com >
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

import unittest
from StringIO import StringIO

import subflip

def flip_str(src):
    f_src = StringIO(src)
    f_dst = StringIO()
    subflip.flipfile(f_src, f_dst)
    return f_dst.getvalue()
    

class SUBTestCase(unittest.TestCase):
    def test_basic(self):
        src = u"""
{789}{863}.ניסיון 123|.שורה שנייה
{1162}{1238}?האמנם -|.Indeed
"""
        dst = u"""
{789}{863}.123 ןויסינ|.היינש הרוש
{1162}{1238}?םנמאה -|.Indeed
"""
        self.assertEqual(flip_str(src), dst)

    def test_mirror(self):
        src = u"""
{1}{2}(,שלום (כך אני אומר|.בהחלט
"""
        dst = u"""
{1}{2}(,רמוא ינא ךכ) םולש|.טלחהב
"""
        self.assertEqual(flip_str(src), dst)
        


if __name__ == '__main__':
    unittest.main()
